package com.longkey.workflow.client.view
{
	import com.longkey.workflow.client.control.Context;
	import com.longkey.workflow.client.control.Model;
	import com.longkey.workflow.client.selector.SelectorUtil;
	
	import flash.events.MouseEvent;
	import flash.ui.ContextMenu;
	
	import mx.controls.Alert;
	import mx.controls.ColorPicker;
	import mx.controls.LinkButton;
	import mx.managers.PopUpManager;
	import mx.skins.spark.ColorPickerSkin;
	
	import spark.components.BorderContainer;
	import spark.components.Button;
	import spark.components.Group;
	import spark.components.ToggleButton;
	import spark.components.supportClasses.ButtonBarHorizontalLayout;
	import spark.layouts.HorizontalLayout;
	
	import org.longkey.portal.MaskUtil;
	import org.longkey.portal.Portal;
	
	public class WFToolBar extends BorderContainer
	{
		private static var instance:WFToolBar;
		
		[Embed(source="/img/toolbar/save.gif")]
		private static var saveIcon : Class;
		private var saveBtn:LinkButton;
		
		[Embed(source="/img/test_16.png")]
		private static var testIcon:Class;
		private var testBtn:ToggleButton;
		
		private var colorPicker:ColorPicker;
		
		public function WFToolBar()
		{
			super();
			init();
		}
		
		private function init():void{
			instance = this;
			this.height = 25;
			this.percentWidth = 100;
			this.setStyle("borderVisible",false);
			
			var layout:HorizontalLayout = new HorizontalLayout();
			layout.paddingLeft = 10;
			layout.gap = 5;
			this.layout = layout;
			
			saveBtn = new LinkButton();
			saveBtn.setStyle("icon", saveIcon);
			saveBtn.width = 20;
			saveBtn.toolTip = "保存";
			saveBtn.addEventListener(MouseEvent.CLICK, test);
			
			this.addElement(saveBtn);
			
			testBtn = new ToggleButton();
			testBtn.setStyle("icon", testIcon);
			testBtn.width = 21;
			testBtn.height = 21;
			testBtn.addEventListener(MouseEvent.CLICK, testBtnHandle);
			this.addElement(testBtn);

			colorPicker = new ColorPicker();
//			colorPicker.setStyle("skinClass", ColorPickerSkin);
//			colorPicker.parent
//			colorPicker.selectedColor = 0xFFFFFF;
			this.addElement(colorPicker);
		}
		
		public static function getInstance():WFToolBar{
			return instance;
		}
		
		protected function testBtnHandle(event:MouseEvent):void{
			var cp:ColorPicker = new ColorPicker();
			cp.selectedColor = 0xFFFFFF;
//			var bd:BorderContainer = new BorderContainer();
//			bd.addElement(cp);
			PopUpManager.addPopUp(cp, SelectorUtil.target);
			PopUpManager.centerPopUp(cp);
			
		}
		
		public static function test(event:MouseEvent):void{
//			MaskUtil.info("请稍候...", 3000);
//			MaskUtil.wait(null, 3000);
//			MaskUtil.error("出错了。。。");
//			var params:Object = new Object();
//			params["time"] = 5;
//			Portal.execjava(fun, "portalTestBean.waitting"); 
			SelectorUtil.dataGridSelect(5, "", fun, false, "dev0");
		}
		
		private static function fun(ret:Array):void{
			Alert.show(ret[0] + ";" + ret[1]);
		}
	}
}